上一篇介紹了一個 package 該有哪些內容,今天來介紹每個內容是什麼
Move package 在 Move.toml 中定義
最基本配置
[package]
name = "AName"
version = "0.0.0"
進階配置
[package]
name = <string> # e.g., "MoveStdlib"
version = "<uint>.<uint>.<uint>" # e.g., "0.1.1"
license* = <string> # e.g., "MIT", "GPL", "Apache 2.0"
authors* = [<string>] # e.g., ["Joe Smith (joesmith@noemail.com)", "Jane Smith (janesmith@noemail.com)"]
[addresses] # (Optional section) Declares named addresses in this package and instantiates named addresses in the package graph
# One or more lines declaring named addresses in the following format
<addr_name> = "_" | "<hex_address>" # e.g., Std = "_" or Addr = "0xC0FFEECAFE"
[dependencies] # (Optional section) Paths to dependencies and instantiations or renamings of named addresses from each dependency
# One or more lines declaring dependencies in the following format
<string> = { local = <string>, addr_subst* = { (<string> = (<string> | "<hex_address>"))+ } } # local dependencies
<string> = { git = <URL ending in .git>, subdir=<path to dir containing Move.toml inside git repo>, rev=<git commit hash>, addr_subst* = { (<string> = (<string> | "<hex_address>"))+ } } # git dependencies
[dev-addresses] # (Optional section) Same as [addresses] section, but only included in "dev" and "test" modes
# One or more lines declaring dev named addresses in the following format
<addr_name> = "_" | "<hex_address>" # e.g., Std = "_" or Addr = "0xC0FFEECAFE"
[dev-dependencies] # (Optional section) Same as [dependencies] section, but only included in "dev" and "test" modes
# One or more lines declaring dev dependencies in the following format
<string> = { local = <string>, addr_subst* = { (<string> = (<string> | <address>))+ } }
[package]
name = "AName"
version = "0.0.0"
license = "Apache 2.0"
[addresses]
AddressToBeFilledIn = "_"
SpecifiedAddress = "0xB0B"
[dependencies]
# Local dependency
LocalDep = { local = "projects/move-awesomeness", addr_subst = { "Std" = "0x1" } }
# Git dependency
MoveStdlib = { git = "https://github.com/diem/diem.git", subdir="language/move-stdlib", rev = "56ab033cc403b489e891424a629e76f643d4fb6b" }
[dev-addresses] # For use when developing this module
AddressToBeFilledIn = "0x101010101"
在 Move package 中,可以直接在裡面聲明地址,實例化範圍內的其他命名地址,並從 Move package 系統清單文件中的其他 package 重命名地址
custom module
文件位置為: example_pkg/sources/A.move
module NamedAddr::A {
public fun x(): address { @NamedAddr }
}
我們可以在 example_pkg/Move.toml
用兩種不同的方式聲明命名地址 NamedAddr
[package]
name = "ExamplePkg" // 未分配的命名地址,可以稍後通過導入 package 進行實例化
..
[addresses]
NamedAddr = "0xCAFE" // 分配的命名地址,為準確地址,且不能更改
只要命名地址始終具有相同的值,就可以在包圖中多次實例化命名地址。如果在整個 package 中使用不同的值實例化相同的命名地址(無論是否重命名),則會出現錯誤。
[package]
name = "ExamplePkg"
...
[addresses]
NamedAddr = "_"
[dev-addresses]
NamedAddr = "0xC0FFEE" // 不會在此模式之外的地方編譯
Move CLI 可以針對 package 可以使用這些指令
$move package <package_flags> <command> <command_flags>
$move package --help